//
//  ProductDetailWebFooterView.m
//  ExhibitionHall
//
//  Created by 王洋 on 2019/6/13.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "ProductDetailWebFooterView.h"

@interface ProductDetailWebFooterView ()<WKNavigationDelegate>

@property (nonatomic, strong)WKWebView *webView;

@property (nonatomic, copy)NSString * htmlStr;

@property (nonatomic, strong)UIActivityIndicatorView *indicatorView;

@end

@implementation ProductDetailWebFooterView

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        
        [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsZero);
        }];
        
        [self.indicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsZero);
        }];
    }
    return self;
}
- (void)reloadHtmlWithStr:(NSString *)htmlStr {

    [self.indicatorView startAnimating];
//    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.jianshu.com/p/ce0f0055248e"]]];

    
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:htmlStr]]];

}

- (WKWebView *)webView {
    if (!_webView) {
        _webView = [[WKWebView alloc] init];
        _webView.scrollView.scrollEnabled = NO;
        _webView.tag = 101;
        _webView.navigationDelegate = self;
        if (@available(iOS 11.0, *)) {
            _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        [self.contentView addSubview:_webView];
    }
    return _webView;
}

- (UIActivityIndicatorView *)indicatorView {
    if (!_indicatorView) {
        _indicatorView = [[UIActivityIndicatorView alloc] init];
        _indicatorView.hidesWhenStopped = YES;
        _indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
        [self.contentView addSubview:_indicatorView];
    }
    return _indicatorView;
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
    [_indicatorView stopAnimating];
    if ([self.navigationDelegate respondsToSelector:@selector(webView:didFinishNavigation:)]) {
        [self.navigationDelegate webView:webView didFinishNavigation:navigation];
    }
}
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
}

@end
